﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LanDBom.Models.Contracts
{
    public class Modlfy_Contracts
    {
        LDbaseEntities LD = new LDbaseEntities();
        public Designdraw getDes(string bianhao)
        {
            Designdraw designdraw = LD.Designdraw.SingleOrDefault(x => x.D_Ton == bianhao);
            return designdraw;
        }
        public int EditDes(Designdraw designdraw)
        {
            Designdraw des = getDes(designdraw.D_Ton);

            des.D_Applic = designdraw.D_Applic;
            des.D_reDate = designdraw.D_reDate;
            des.D_price = designdraw.D_price;
            des.D_take = designdraw.D_take;
            des.D_App = designdraw.D_App;
            des.D_AppRevi = designdraw.D_AppRevi;
            des.D_Ton = designdraw.D_Ton;
            des.D_CN = designdraw.D_CN;
            des.D_PN = designdraw.D_PN;
            des.D_DE = designdraw.D_DE;
            des.D_LV = designdraw.D_LV;
            des.D_DT = designdraw.D_DT;
            des.D_PW = designdraw.D_PW;
            des.D_SI = designdraw.D_SI;
            des.D_OI = designdraw.D_OI;
            des.D_MOF = designdraw.D_MOF;
            des.D_PT = designdraw.D_PT;
            des.D_PR = designdraw.D_PR;
            des.D_OR = designdraw.D_OR;
            des.D_SR = designdraw.D_SR;
            des.D_PA = designdraw.D_PA;
            des.D_REC = designdraw.D_REC;
            des.D_AR = designdraw.D_AR;
            des.D_CD = designdraw.D_CD;
            des.D_TCA = designdraw.D_TCA;
            des.D_dhr = designdraw.D_dhr;
            des.D_dhly = designdraw.D_dhly;
            des.D_zhuang = designdraw.D_zhuang;

            return LD.SaveChanges();
        }

        /// <summary>
        /// 根据委托单id查找委托单的方法
        /// </summary>
        /// <param name="bom_id"></param>
        /// <returns></returns>
        public Design getdes(int bom_id)
        {
            Design nda = LD.Design.SingleOrDefault(x => x.DE_id == bom_id);

            return nda;
        }
        /// <summary>
        /// 修改设计图设计时间的方法
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        public int Changedestime(Design de)
        {
            Design des = getdes(de.DE_id);
            des.DE_Slong = de.DE_Slong;
            return LD.SaveChanges();
        }
        /// <summary>
        /// 设计图呗驳回的方法
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        public int Changedes(Design de)
        {
            Design des = getdes(de.DE_id);
            des.DE_wenjain = de.DE_wenjain;
            des.DE_JDR = de.DE_JDR;
            des.DE_tuiLei = de.DE_tuiLei;
            return LD.SaveChanges();
        }
        /// <summary>
        /// 设计图通过审核的方法
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        public int Changedes3(Design de)
        {
            Design des = getdes(de.DE_id);
            des.DE_JDR = de.DE_JDR;
            des.DE_tuiLei = de.DE_tuiLei;
            des.DZ_Fnajm = de.DZ_Fnajm;
            des.DZ_ShTIme = de.DZ_ShTIme;
            return LD.SaveChanges();
        }
        /// <summary>
        /// 根据委托单号查找委托单的方法
        /// </summary>
        /// <param name="bom_id"></param>
        /// <returns></returns>
        public Designdraw getdes2(string bom_id)
        {
            Designdraw nda = LD.Designdraw.SingleOrDefault(x => x.D_Ton == bom_id);

            return nda;
        }
        /// <summary>
        /// 修改委托单状态，完成审核人，完成时间的方法
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        public int Changedes2(Designdraw de)
        {
            Designdraw des = getdes2(de.D_Ton);
            des.D_zhuang = de.D_zhuang;
            des.D_CD = de.D_CD;
            des.D_TCA = de.D_TCA;
            des.DFToDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            return LD.SaveChanges();
        }


        /// <summary>
        /// 格局id查找到代办内容
        /// </summary>
        /// <param name="bom_id"></param>
        /// <returns></returns>
        public Freight getfr(int bom_id)
        {
            Freight nda = LD.Freight.SingleOrDefault(x => x.Fr_id == bom_id);

            return nda;
        }
        
        /// <summary>
        /// 修改代办状态的方法
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        public int Changefr(Freight de)
        {
            Freight des = getfr(de.Fr_id);
            des.Fr_zhuang = de.Fr_zhuang;
            return LD.SaveChanges();
        }

        /// <summary>
        /// 根据申请单号查找申请单
        /// </summary>
        /// <param name="bian"></param>
        /// <returns></returns>
        public Applications getapp(string bian)
        {
            Applications nda = LD.Applications.SingleOrDefault(x => x.AP_bian == bian);

            return nda;
        }
        /// <summary>
        /// 修改申请单号步骤的方法
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        public int Changeapp(Applications de)
        {
            Applications des = getapp(de.AP_bian);
            des.App_bu = de.App_bu;
            des.App_JL = de.App_JL;
            return LD.SaveChanges();

        }
    }
}